package com.example.moviegroup.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseExpandableListAdapter;
import android.widget.ExpandableListView;
import android.widget.ImageView;
import android.widget.TextView;

import com.example.moviegroup.R;

/**
 * Created by walymin-love on 2015/11/18.
 */
public class ExpandAdapter extends BaseExpandableListAdapter {

    private int[] imag = {R.mipmap.cus_ic_huodong,R.mipmap.me_order};
    private String[] action = {"我的活动","我的订单"};
    private String[][] values = {{"VIP活动","诚信活动","购票活动"},{"购物订单","兑换订单","抽奖订单"}};
    private LayoutInflater infla;

    public ExpandAdapter (Context context){
        infla = LayoutInflater.from(context);
    }

    @Override
    public int getGroupCount() {
        return action.length;
    }

    @Override
    public int getChildrenCount(int groupPosition) {
        return values[groupPosition].length;
    }

    @Override
    public Object getGroup(int groupPosition) {
        return null;
    }

    @Override
    public Object getChild(int groupPosition, int childPosition) {
        return null;
    }

    @Override
    public long getGroupId(int groupPosition) {
        return 0;
    }

    @Override
    public long getChildId(int groupPosition, int childPosition) {
        return 0;
    }

    @Override
    public boolean hasStableIds() {
        return false;
    }

    @Override
    public View getGroupView(int groupPosition, boolean isExpanded, View convertView, ViewGroup parent) {
        ViewHolder hodler;
        if(convertView == null){
            hodler = new ViewHolder();
            convertView = infla.inflate(R.layout.exp_l1,null);
            hodler.tv = (TextView) convertView.findViewById(R.id.tv_item1);
            hodler.iv = (ImageView) convertView.findViewById(R.id.iv_hander);
            convertView.setTag(hodler);
        }else {
            hodler = (ViewHolder) convertView.getTag();
        }
        hodler.tv.setText(action[groupPosition]);
        hodler.iv.setImageResource(imag[groupPosition]);
        return convertView;
    }

    @Override
    public View getChildView(int groupPosition, int childPosition, boolean isLastChild, View convertView, ViewGroup parent) {
        ViewHolder hodler;
        if(convertView == null){
            hodler = new ViewHolder();
            convertView = infla.inflate(R.layout.exp_l2,null);
            hodler.tv = (TextView) convertView.findViewById(R.id.tv_item1);
            convertView.setTag(hodler);
        }else {
            hodler = (ViewHolder) convertView.getTag();
        }
        hodler.tv.setText(values[groupPosition][childPosition]);
        return convertView;
    }

    @Override
    public boolean isChildSelectable(int groupPosition, int childPosition) {
        return true;
    }
    class ViewHolder{
        TextView tv;
        ImageView iv;
    }
}
